package com.wx.business.course.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.eachonline.mapper.GenericMapper;
import com.eachonline.service.GenericServiceImpl;
import com.wx.business.course.IxbBusinessPictureService;
import com.wx.business.course.IxbCourseCollectService;
import com.wx.business.course.IxbCourseDetailService;
import com.wx.business.course.IxbTrainingAgencyService;
import com.wx.dao.mapper.IxbCourseCollectMapper;
import com.wx.model.IxbBusinessPicture;
import com.wx.model.IxbCourseCollect;
import com.wx.model.IxbCourseCollectExample;
import com.wx.model.IxbCourseDetail;
import com.wx.model.IxbTrainingAgency;
@Service("ixbCourseCollectService")
public class IxbCourseCollectServiceImpl extends GenericServiceImpl<IxbCourseCollect, IxbCourseCollectExample, String> implements IxbCourseCollectService  {

	private static final  Logger logger =Logger.getLogger(IxbCourseCollectServiceImpl.class);

	@Resource
	private IxbCourseCollectMapper ixbCourseCollectMapper;
	
	@Resource
	private IxbCourseDetailService ixbCourseDetailService;
	
	@Resource
	private IxbBusinessPictureService ixbBusinessPictureService;
	
	@Resource
	private IxbTrainingAgencyService ixbTrainingAgencyService;
	
	@Override
	protected GenericMapper<IxbCourseCollect, IxbCourseCollectExample, String> getGenericMapper() {
		return ixbCourseCollectMapper;
	}

	@Override
	public void addCourseCollect(IxbCourseDetail courseDetail, String userId) {
		// TODO Auto-generated method stub
		IxbTrainingAgency agency=ixbTrainingAgencyService.selectByPrimaryKey(courseDetail.getPublisherId());
		IxbBusinessPicture businessPic=ixbBusinessPictureService.queryCourseMainPicture(courseDetail.getSid());
		IxbCourseCollect courseCollect=new IxbCourseCollect();
		courseCollect.setCourseAgency(agency.getAgencyName());
		courseCollect.setCourseId(courseDetail.getSid());
		courseCollect.setCoursePicUrl(businessPic.getBusinessPicUrl());
		courseCollect.setCoursePrice(courseDetail.getCoursePrice());
		courseCollect.setCourseTitle(courseDetail.getCourseTitle());
		courseCollect.setUserId(userId);
		courseCollect.setCreateTime(new Date());
		insert(courseCollect);
		
		ixbCourseDetailService.updateCourseCollectNum(courseDetail.getSid());
	}

	@Override
	public List<Map<String, Object>> selectCourseCollectList(String userId) {
		// TODO Auto-generated method stub
		return ixbCourseCollectMapper.queryCourseCollectList(userId);
	}


}
